package com.cuijq.ms.flyweight.v4;

import java.awt.Font;
import java.util.ArrayList;
import java.util.List;

/**
 * @author by CuiJQ
 * @Classname CharacterStyleFactory
 * @Description CharacterStyleFactory Description
 * @Date 2021/5/27 0:04
 */
public class CharacterStyleFactory {

  private static final List<CharacterStyle> styles = new ArrayList<>();

  public static CharacterStyle getStyle(Font font, int size, int colorRGB) {
    CharacterStyle newStyle = new CharacterStyle(font, size, colorRGB);
    for (CharacterStyle style : styles) {
      if (style.equals(newStyle)) {
        return style;
      }
    }
    styles.add(newStyle);
    return newStyle;
  }
}
